using System;

namespace BlobSim
{
    class RotationSpeedDampenerLinear : RotationSpeedDampener
    {
        private const float DefaultRadiansPerSecond = 0.5f;

        private float _radiansPerSecond = DefaultRadiansPerSecond;

        public float RadiansPerSecond
        {
            get { return _radiansPerSecond; }
            set
            {
                if (value <= 0)
                    throw new ArgumentOutOfRangeException("value", "value must be greater than zero");

                _radiansPerSecond = value;
            }
        }

        public override float GetNewSpeed(float speed, TimeSpan delta)
        {
            if (speed < 0)
                throw new ArgumentOutOfRangeException("speed", "value must be a positive number");

            var speedDelta = (float) (_radiansPerSecond*delta.TotalSeconds);
            
            if (speed <= speedDelta) return 0.0f;

            var newSpeed = speed + speedDelta;

            if (ShouldStop(newSpeed)) return 0.0f;

            return newSpeed;
        }
    }
}
